package com.cskaoyan.servlet;

import com.cskaoyan.bean.MarketAdmin;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.service.AdminService;
import com.cskaoyan.service.AdminServiceImpl;
import com.cskaoyan.util.JacksonUtil;
import lombok.SneakyThrows;


import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/admin/admin/*")
public class AdminAdminServlet extends WdBaseServlet {
    AdminService adminAdminService= new AdminServiceImpl();

    private BaseRespVo list(HttpServletRequest request, HttpServletResponse response){
        String pageStr = request.getParameter("page");
        Integer page = Integer.parseInt(pageStr);
        String limitStr = request.getParameter("limit");
        Integer limit = Integer.parseInt(limitStr);
        String sort = request.getParameter("sort");
        String oder = request.getParameter("order");
        String username = request.getParameter("username");


        BaseRespVo baseRespVo = adminAdminService.list(page,limit,sort,oder,username);

        return baseRespVo;
    }

    @SneakyThrows
    private BaseRespVo create(HttpServletRequest request, HttpServletResponse response){
        String s = request.getReader().readLine();
        MarketAdmin admin = JacksonUtil.read(s, MarketAdmin.class);

        BaseRespVo baseRespVo = adminAdminService.create(admin);
        return baseRespVo;
    }
    @SneakyThrows
    private BaseRespVo update(HttpServletRequest request, HttpServletResponse response){
        String s = request.getReader().readLine();
        MarketAdmin admin = JacksonUtil.read(s, MarketAdmin.class);

        BaseRespVo baseRespVo = adminAdminService.updatet(admin);

        return baseRespVo;
    }
    @SneakyThrows
    private BaseRespVo delete(HttpServletRequest request, HttpServletResponse response){

        String s = request.getReader().readLine();
        MarketAdmin admin = JacksonUtil.read(s, MarketAdmin.class);

        BaseRespVo baseRespVo = adminAdminService.delete(admin);

        return baseRespVo;
    }

}
